// pages/profile/contact.js
import api from '../../utils/api'
Page({
  data: {
    venue_name: '南京中医药大学校史馆',
    open_time: '周一至周五：09:00-16:30，16:00停止入馆，双休日及法定节假日闭馆',
    address: '南京中医药大学仙林校区自信楼（江苏省中医药博物馆）3楼',
    phone: '025-85811666',
    email: 'nzy@nzy.edu.cn',
    subway: '2号线羊山公园站1号出口步行10分钟',
    bus: 'D1路、97路、321路中医药大学站',
    enter_notice: '',
  },

  onLoad() {
    // 获取基础配置项
    this.get_museum_config();
  },

  // 获取配置项
  async get_museum_config() {
    const data = await api.museum_config.getList()
    let updateData = {};
    // 把请求回来的配置项赋值
    if (data.venue_name.config_value) updateData['venue_name'] = data.venue_name.config_value;
    if (data.open_time.config_value) updateData['open_time'] = data.open_time.config_value;
    if (data.address.config_value) updateData['address'] = data.address.config_value;
    if (data.phone.config_value) updateData['phone'] = data.phone.config_value;
    if (data.email.config_value) updateData['email'] = data.email.config_value;
    if (data.subway.config_value) updateData['subway'] = data.subway.config_value;
    if (data.bus.config_value) updateData['bus'] = data.bus.config_value;
    if (data.enter_notice.config_value) updateData['enter_notice'] = data.enter_notice.config_value;
    this.setData(updateData);
    
  },

  // 拨打电话
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.phone
    })
  },

  // 复制邮箱
  copyEmail() {
    wx.setClipboardData({
      data: this.data.email,
      success: () => {
        wx.showToast({
          title: '邮箱已复制',
          icon: 'success'
        })
      }
    })
  },

  // 打开地图导航
  openMap() {
    wx.openLocation({
      latitude: 32.104726,
      longitude: 118.945326,
      name: '南京中医药大学校史馆',
      address: this.data.address,
      scale: 15
    })
  }
})